<template>
    <div v-if="visible" :class="['message-box', messageType]" @click="hideMessage">
      <span>{{ message }}</span>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        visible: false,
        message: '',
        messageType: ''
      };
    },
    methods: {
      showMessage(msg, type) {
        this.message = msg;
        this.messageType = type;
        this.visible = true;
  
        // 自动隐藏提示消息
        setTimeout(() => {
          this.hideMessage();
        }, 3000);
      },
      hideMessage() {
        this.visible = false;
      }
    }
  };
  </script>
  
  <style scoped>
  .message-box {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px;
    border-radius: 5px;
    color: white;
    font-weight: bold;
    z-index: 1000;
    transition: opacity 0.5s;
  }
  
  .message-box.success {
    background-color: #4caf50; /* 绿色 */
  }
  
  .message-box.error {
    background-color: #f44336; /* 红色 */
  }
  
  .message-box.warning {
    background-color: #ff9800; /* 橙色 */
  }
  
  .message-box.info {
    background-color: #2196f3; /* 蓝色 */
  }
  </style>
  